package cn.minsh.lims.eoms.modules.app.service.impl;

import cn.minsh.lims.eoms.common.utils.PageUtils;
import cn.minsh.lims.eoms.common.utils.Query;
import cn.minsh.lims.eoms.modules.app.service.PicService;
import cn.minsh.lims.eoms.modules.app.dao.PicDao;
import cn.minsh.lims.eoms.modules.app.entity.PicEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("picService")
public class PicServiceImpl extends ServiceImpl<PicDao, PicEntity> implements PicService {

    @Autowired
    private PicDao picDao ;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PicEntity> page = this.page(
                new Query<PicEntity>().getPage(params),
                new QueryWrapper<PicEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void deleteByTypeAndBusiId(Integer type, Long busiId) {
        QueryWrapper<PicEntity> picEntityQueryWrapper = new QueryWrapper<>() ;
        picEntityQueryWrapper.eq("type",type) ;
        picEntityQueryWrapper.eq("busi_id",busiId);
        picDao.delete(picEntityQueryWrapper) ;
    }

    @Override
    public List<PicEntity> listByTypeAndBusiId(Integer type, Long busiId) {
        QueryWrapper<PicEntity> picEntityQueryWrapper = new QueryWrapper<>() ;
        picEntityQueryWrapper.eq("type",type) ;
        picEntityQueryWrapper.eq("busi_id",busiId);
        return picDao.selectList(picEntityQueryWrapper);
    }

    @Override
    public List<PicEntity> listByType(Integer type) {
        QueryWrapper<PicEntity> picEntityQueryWrapper = new QueryWrapper<>() ;
        picEntityQueryWrapper.eq("type",type) ;
        return picDao.selectList(picEntityQueryWrapper);
    }
}